struct cmp
{
    bool operator()(int a, int b) { return a > b; }
};

class KthLargest {
public:
    priority_queue<int, vector<int>, cmp> que;
    int n;
    KthLargest(int k, vector<int>& nums) {
        n = k;
        for (auto& x : nums)
        {
            if (que.size() < k) que.push(x);
            else
            {
                if (x > que.top())
                {
                    que.pop();
                    que.push(x);
                }
            }
        }
    }

    int add(int val) {
        if (que.size() < n) que.push(val);
        else if (val > que.top())
        {
            que.pop();
            que.push(val);
        }
        return que.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */